/**
 * Desc:
 * Created by PhpStorm.
 * User: shantong
 * Date: 2018/7/2
 * Time: 16:27
 */

export const getFormItemLayout = (labelXs=24, labelSm=8, wrapperXs=24, wrapperSm=16) => {
	return {
		labelCol: {
			xs: { span: labelXs },
			sm: { span: labelSm },
		},
		wrapperCol: {
			xs: { span: wrapperXs },
			sm: { span: wrapperSm },
		},
	}
}

export const getTailFormItemLayout = (xsSpan=24, xsOffset=0, smSpan=16, smOffset=8) => {
	return {
		wrapperCol: {
			xs: {
				span: xsSpan,
				offset: xsOffset,
			},
			sm: {
				span: smSpan,
				offset: smOffset,
			},
		},
	}
}

const add0 = v => v < 10 ? `0${v}` : v;

export const dateFormat = (timestamp) => {
	if (timestamp == '' || timestamp == 0) {
		return '';
	}
	timestamp = parseInt(timestamp) * 1000;
	timestamp = new Date(timestamp)
	let year = timestamp.getFullYear();
	let month = timestamp.getMonth()+1;
	let date = timestamp.getDate();
	let hour = timestamp.getHours();
	let minute = timestamp.getMinutes();
	let second = timestamp.getSeconds();

	return  `${year}-${add0(month)}-${add0(date)} ${add0(hour)}:${add0(minute)}:${add0(second)}`;
}